
import org.jcsp.lang.*;
import org.jcsp.plugNplay.ints.*;

public class JcspTable {


  public static void  main (String argv []) {

    System.out.println ("");
    System.out.println ("This version uses *symmetric* channels");
    System.out.println ();

    SpuriousLog.start ();

    final int nPhil = 5;
    System.out.println (nPhil + " iterations per timing ...\n");

    JcspPhil[] phils = new JcspPhil[nPhil];
    One2OneChannelSymmetricInt[] chan1 = new One2OneChannelSymmetricInt[nPhil];
    One2OneChannelSymmetricInt[] chan2 = new One2OneChannelSymmetricInt[nPhil];
    for (int j=0;j<nPhil;j++) {
    	chan1 [j] = Channel.one2oneSymmetricInt ();
    	chan2 [j] = Channel.one2oneSymmetricInt ();
    }
    for (int i=0;i<nPhil;i++) {
    	if ((i > 0 ) && (i <nPhil-2)) {
    		phils[i] = new JcspPhil(i, chan1[i-1].in(),chan1 [i+1].in(),chan2 [i-1].out(),chan2[i+1].out());
    	}
    	
    	else 
    	if (i == 0 ) {
    		phils[i] = new JcspPhil(i,chan1[nPhil-1].in(),chan1 [i+1].in(),chan2[nPhil-1].out(),chan2[i+1].out());    		
    		}
    	else 
    	if (i == nPhil-1) { 
    		phils[i] = new JcspPhil(i,chan1[i-1].in(),chan1 [0].in(),chan2 [i-1].out(),chan2[0].out());
    	}
    	
    }
     
      new Parallel (
       new CSProcess[] {
        		new Parallel
        		(phils)       
        }
      ).run ();


    System.out.println ("\n\n\nOnly gets here if all above parallel processes fail ...\n\n\n");

  }

}